<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        
        
        
        <link rel="shortcut icon" href="../img/favicon.ico">
        <title>Web3.shh - Web3.js 0.20官方文档中文版</title>
        <link href="../css/bootstrap-custom.min.css" rel="stylesheet">
        <link href="../css/font-awesome.min.css" rel="stylesheet">
        <link href="../css/base.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
        <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
            <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->

        <script src="../js/jquery-1.10.2.min.js" defer></script>
        <script src="../js/bootstrap-3.0.3.min.js" defer></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
        <script>hljs.initHighlightingOnLoad();</script> 
    </head>

    <body>

        <div class="navbar navbar-default navbar-fixed-top" role="navigation">
            <div class="container">

                <!-- Collapsed navigation -->
                <div class="navbar-header">
                    <!-- Expander button -->
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="..">Web3.js 0.20官方文档中文版</a>
                </div>

                <!-- Expanded navigation -->
                <div class="navbar-collapse collapse">
                        <!-- Main navigation -->
                        <ul class="nav navbar-nav">
                            <li >
                                <a href="https://web3.learnblockchain.cn">首页</a>
                            </li>
                            <li >
                                <a href="..">0.20文档</a>
                            </li>
                            <li >
                                <a href="https://learnblockchain.cn">深入浅出区块链</a>
                            </li>
                            <li >
                                <a href="https://wiki.learnblockchain.cn/images/dapp.png">DAPP视频课程</a>
                            </li>
                        </ul>

                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="#" data-toggle="modal" data-target="#mkdocs_search_modal">
                                <i class="fa fa-search"></i> Search
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

        <div class="container">
                <div class="col-md-3"><div class="bs-sidebar hidden-print affix well" role="complementary">
    <ul class="nav bs-sidenav">
        <li class="main active"><a href="#web3shh">web3.shh</a></li>
            <li><a href="#_1">示例</a></li>
            <li><a href="#web3shhpost">web3.shh.post</a></li>
            <li><a href="#web3shhnewidentity">web3.shh.newIdentity</a></li>
            <li><a href="#web3shhhasidentity">web3.shh.hasIdentity</a></li>
            <li><a href="#web3shhnewgroup">web3.shh.newGroup</a></li>
            <li><a href="#web3shhaddtogroup">web3.shh.addToGroup</a></li>
            <li><a href="#web3shhfilter">web3.shh.filter</a></li>
    </ul>
</div></div>
                <div class="col-md-9" role="main">

<h2 id="web3shh">web3.shh</h2>
<p>Whisper协议相关的API，可参考<a href="https://github.com/ethereum/wiki/wiki/Whisper-Overview">Whisper  Overview</a></p>
<h3 id="_1">示例</h3>
<pre><code class="js">var shh = web3.shh;
</code></pre>

<hr />
<h3 id="web3shhpost">web3.shh.post</h3>
<p>web3.shh.post(object [, callback])</p>
<p>调用post()方法向以太坊网络发送whisper消息.</p>
<h4 id="_2">参数</h4>
<ol>
<li><code>Object</code> - 要发送的对象:</li>
<li><code>from</code>: <code>String</code>, 60 Bytes HEX - (可选) 发送者</li>
<li><code>to</code>: <code>String</code>, 60 Bytes  HEX - (可选) 接收者. 仅有接收者能解密消息。</li>
<li><code>topics</code>: <code>Array of Strings</code> - 主题数组, 为了接收者能区分消息.</li>
<li><code>payload</code>: <code>String|Number|Object</code> - 消息负载.</li>
<li><code>priority</code>: <code>Number</code> - 优先级</li>
<li><code>ttl</code>: <code>Number</code> - 存活时间（秒）
2.<code>callback</code> <code>Function</code> - 可选的回调函数，设置此参数后函数将采用异步http请求节点API.</li>
</ol>
<h4 id="_3">返回值</h4>
<p><code>Boolean</code> - 消息成功发送后返回true，否则返回false.</p>
<h4 id="_4">示例</h4>
<pre><code class="js">var identity = web3.shh.newIdentity();
var topic = '示例';
var payload = 'hello whisper world!';

var message = {
  from: identity,
  topics: [topic],
  payload: payload,
  ttl: 100,
  workToProve: 100 // or priority TODO
};

web3.shh.post(message);
</code></pre>

<hr />
<h3 id="web3shhnewidentity">web3.shh.newIdentity</h3>
<pre><code>web3.shh.newIdentity([callback])
</code></pre>
<p>调用newIdentity()方法创建一个新的id.</p>
<h4 id="_5">参数</h4>
<ol>
<li><code>callback``Function</code> - 可选的回调函数，设置此参数时函数将采用异步http来请求节点旳API.</li>
</ol>
<h4 id="_6">返回值</h4>
<p><code>String</code> - 新id，以16进制字符串表示.</p>
<h4 id="_7">示例</h4>
<pre><code class="js">var identity = web3.shh.newIdentity();
console.log(identity); // &quot;0xc931d93e97ab07fe42d923478ba2465f283f440fd6cabea4dd7a2c807108f651b7135d1d6ca9007d5b68aa497e4619ac10aa3b27726e1863c1fd9b570d99bbaf&quot;
</code></pre>

<hr />
<h3 id="web3shhhasidentity">web3.shh.hasIdentity</h3>
<pre><code>web3.shh.hasIdentity(identity, [callback])
</code></pre>
<p>调用hasIdentity()方法检查用户是否有指定的id.</p>
<h4 id="_8">参数</h4>
<ol>
<li><code>identity``String</code> - 要检查的id.</li>
<li><code>callback``Function</code> - 可选的回调函数，设置此参数后函数将采用异步http来请求节点API.</li>
</ol>
<h4 id="_9">返回值</h4>
<p><code>Boolean</code> - 如果指定的id存在则返回true，否则返回false.</p>
<h4 id="_10">示例</h4>
<pre><code class="js">var identity = web3.shh.newIdentity();
var result = web3.shh.hasIdentity(identity);
console.log(result); // true

var result2 = web3.shh.hasIdentity(identity + &quot;0&quot;);
console.log(result2); // false
</code></pre>

<hr />
<h3 id="web3shhnewgroup">web3.shh.newGroup</h3>
<h4 id="_11">示例</h4>
<pre><code class="js">// TODO: not implemented yet
</code></pre>

<hr />
<h3 id="web3shhaddtogroup">web3.shh.addToGroup</h3>
<h4 id="_12">示例</h4>
<pre><code class="js">// TODO: not implemented yet
</code></pre>

<hr />
<h3 id="web3shhfilter">web3.shh.filter</h3>
<pre><code class="js">var filter = web3.shh.filter(options)

// watch for changes
filter.watch(function(error, result){
  if (!error)
    console.log(result);
});
</code></pre>

<p>调用web3.ssh.filter()方法来监听接收的whisper消息.</p>
<h4 id="_13">参数</h4>
<ol>
<li><code>options``Object</code> - 过滤器选项:</li>
<li><code>topics</code>: <code>Array of Strings</code> - 主题字符串数组，用来过滤消息，可以如下组合:<ul>
<li><code>['topic1', 'topic2'] == 'topic1' &amp;&amp; 'topic2'</code></li>
<li><code>['topic1', ['topic2', 'topic3']] == 'topic1' &amp;&amp; ('topic2' || 'topic3')</code></li>
<li><code>[null, 'topic1', 'topic2'] == ANYTHING &amp;&amp; 'topic1' &amp;&amp; 'topic2'</code> -&gt; <code>null</code> works as a wildcard</li>
</ul>
</li>
<li><code>to</code>: Filter by identity of receiver of the message. If provided and the node has this identity, it will decrypt incoming encrypted messages.</li>
<li><code>callback``Function</code> - 可选的回调函数，当设置此参数后将采用异步http请求节点旳API.</li>
</ol>
<h4 id="_14">回调函数的返回值</h4>
<p><code>Object</code> - 接收到的消息:</p>
<ul>
<li><code>from</code>: <code>String</code>, 60字节，消息发送者.</li>
<li><code>to</code>: <code>String</code>, 60字节，消息接受者.</li>
<li><code>expiry</code>: <code>Number</code> - 消息过期时间，秒为单位.</li>
<li><code>ttl</code>: <code>Number</code> -  消息存活时间，秒为单位.</li>
<li><code>sent</code>: <code>Number</code> -  消息发送时间，unix时间戳格式.</li>
<li><code>topics</code>: <code>Array of String</code> - 消息包含的主题字符串数组.</li>
<li><code>payload</code>: <code>String</code> - 消息的载荷内容.</li>
<li><code>workProved</code>: <code>Number</code> - 消息发送前需要完成的任务.</li>
</ul>
<hr /></div>
        </div>

        <footer class="col-md-12">
            <hr>
            <p>Documentation built with <a href="https://www.mkdocs.org/">MkDocs</a>.</p>
        </footer>
        <script>
            var base_url = "..",
                shortcuts = {"help": 191, "next": 78, "previous": 80, "search": 83};
        </script>
        <script src="../js/base.js" defer></script>
        <script src="../search/main.js" defer></script>

        <div class="modal" id="mkdocs_search_modal" tabindex="-1" role="dialog" aria-labelledby="Search Modal" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="exampleModalLabel">Search</h4>
            </div>
            <div class="modal-body">
                <p>
                    From here you can search these documents. Enter
                    your search terms below.
                </p>
                <form role="form">
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="Search..." id="mkdocs-search-query" title="Type search term here">
                    </div>
                </form>
                <div id="mkdocs-search-results"></div>
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div><div class="modal" id="mkdocs_keyboard_modal" tabindex="-1" role="dialog" aria-labelledby="Keyboard Shortcuts Modal" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="exampleModalLabel">Keyboard Shortcuts</h4>
            </div>
            <div class="modal-body">
              <table class="table">
                <thead>
                  <tr>
                    <th style="width: 20%;">Keys</th>
                    <th>Action</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td class="help shortcut"><kbd>?</kbd></td>
                    <td>Open this help</td>
                  </tr>
                  <tr>
                    <td class="next shortcut"><kbd>n</kbd></td>
                    <td>Next page</td>
                  </tr>
                  <tr>
                    <td class="prev shortcut"><kbd>p</kbd></td>
                    <td>Previous page</td>
                  </tr>
                  <tr>
                    <td class="search shortcut"><kbd>s</kbd></td>
                    <td>Search</td>
                  </tr>
                </tbody>
              </table>
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div>

    </body>
</html>
